package com.web.kftsdk.entity;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>Title: CertInfoEntity</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/6/13
 */
@Data
@Builder
@AllArgsConstructor
@RequiredArgsConstructor
public class CertInfoEntity {
    public static void main(String[] args) throws Exception{
        Merchant merchant=new Merchant();
        merchant.setMerchantId("rew42342342");
        List<Cert> list=new ArrayList<>();
        list.add(new Cert("44","4242","fdsfsd","/sdfsdf"));
        CertInfoEntity certInfoEntity=new CertInfoEntity();
        certInfoEntity.setMerchant(merchant);
        certInfoEntity.setCerts(list);
        org.apache.commons.io.IOUtils.write(certInfoEntity.toString(),new FileOutputStream(new File("D://log/cert.txt")), Charset.defaultCharset());
    }
    private Merchant merchant;
    private List<Cert> certs;

    @Override
    public String toString() {
        StringBuffer buffer=new StringBuffer();
        buffer.append(JSON.toJSON(merchant)).append("\n");
        certs.forEach(v->   buffer.append(JSON.toJSON(v)).append("\n"));
        return buffer.toString();
    }

    @Data
    @AllArgsConstructor
    @RequiredArgsConstructor
    @Builder
    public static class Merchant{
        private String merchantId;
    }
    @Data
    @AllArgsConstructor
    @RequiredArgsConstructor
    @Builder
    public static class Cert{
        private String no;
        private String merchantType;
        private String certNo;
        private String filePath;
    }

}
